class Solution {
    public int minNumberOfFrogs(String croakOfFrogs) {
        char[] c=croakOfFrogs.toCharArray();
        int[] hash=new int[5];
        String t="croak";
        Map<Character,Integer> index = new HashMap<>(); 
        for(int i=0;i<=4;i++){
            index.put(t.charAt(i),i);
        }
        for(char ch:c){
            if(ch==t.charAt(0)){
                if(hash[4]!=0)
                    hash[4]--;
                hash[0]++;
            }else{
                int i=index.get(ch);
                if(hash[i-1]==0)
                    return -1;
                hash[i-1]--;
                hash[i]++;
            }
        }
        for(int i=0;i<4;i++){
            if(hash[i]!=0)
                return -1;
        }
        return hash[4];
    }
}